﻿using System;
using System.Data;
using ContractManager.Common.Class;
using ContractManager.Common.FormBase;
using ContractManager.BLL.Business;

namespace ContractManager.Reports.TendersDocuments
{
    public partial class FrmBc02 : XtraFormBase
    {
        #region "Form Construction"
        public FrmBc02()
        {
            InitializeComponent();
        }
        #endregion

        private string ReportName = "rptReportBc02";
        #region "Private Method"

        private void BlankForm()
        {
            txtFromDate.EditValue = null;
            txtToDate.EditValue = null;
            txtMbId.EditValue = null;

            txtMbId.Properties.DataSource = ClsMemberBranch.SelectAll();
            txtMbId.Properties.DisplayMember = "MbName";
            txtMbId.Properties.ValueMember = "MbID";
        }

        private void DoPerform()
        {
            string fileName = ReportName;
            string reportName = ClsVariable.GetReportFullPath(fileName);
            int mbId = txtMbId.EditValue == null ? 0 : Convert.ToInt32(txtMbId.EditValue);

            var report = new Stimulsoft.Report.StiReport();
            report.Load(reportName);

            ClsVariable.CreateWaitDialog(ClsVariable.StrCaption, "Vui lòng đợi...");
            ClsVariable.SetWaitDialogCaption("Đang nạp dữ liệu báo cáo...");

            DataTable dtReport = ClsReports.GetReportBc02(txtFromDate.DateTime, txtToDate.DateTime,
                                                          mbId);
            report.RegData(dtReport);
            report.Compile();
            ClsVariable.CloseWaitDialog();
            // In thông tin đơn vị, địa chỉ

            report["KyBaoCao"] = String.Format("Từ ngày {0} Đến ngày {1}", txtFromDate.DateTime.ToString("dd/MM/yyyy"),
                                               txtToDate.DateTime.ToString("dd/MM/yyyy"));
 
            report["DoiTuong"] = String.Format("{0}", txtMbId.Text);
           
            ClsVariable.ApplyReportParam(report, ClsVariable.DtParam);
            report.Show(this.MdiParent);
            //report.Render(true);
            //report.Show();
        }

        #endregion

        #region "Form Event"
        private void FrmBc02_Load(object sender, EventArgs e)
        {
            BlankForm();
        }
        #endregion


        #region "Button Event"
        private void btnOk_Click(object sender, EventArgs e)
        {
            DoPerform();

        }
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        

    }
}
